//
//  ViewController.m
//  GDataBaseDemo
//
//  Created by 高明 on 2020/4/7.
//  Copyright © 2020 WDTX. All rights reserved.
//

#import "ViewController.h"
#import "MJExtension.h"
#import "AreaModel.h"
#import "GMDataBaseTool.h"

@interface ViewController ()

@property (nonatomic,strong) NSMutableArray *dataArr;

@end

@implementation ViewController

-(NSMutableArray *)dataArr {
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"JsonFile" ofType:@"json"];
    NSData *jsonData = [NSData dataWithContentsOfFile:jsonPath];
    if (!jsonData) return;
    NSDictionary *dataDic = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil];
    NSLog(@"%@",dataDic);
    
    NSLog(@"数据库路径：%@",[[GMDataBaseTool sharedTool] getFullPath]);
    
    //删除表
    [[GMDataBaseTool sharedTool] deleteTable];
    
    //创建表
    [[GMDataBaseTool sharedTool] createTable];
    
    //插入数据
    self.dataArr = [AreaModel mj_objectArrayWithKeyValuesArray:dataDic[@"list"]];
    for (AreaModel *model in self.dataArr) {
        [[GMDataBaseTool sharedTool] insertDataWithModel:model];
    }
    
    //读数据
    AreaModel *model = [[GMDataBaseTool sharedTool] getModelWithID:@"2"];
    NSLog(@"name：%@",model.name);
    
    //模糊查询
    NSArray *modelArr = [[GMDataBaseTool sharedTool] getLikeDataWithName:@"Python"];
    NSLog(@"modelArr：%@",modelArr);
}


@end
